package cn.kgc.springboot.service.impl;

import cn.kgc.springboot.entity.User;
import cn.kgc.springboot.mapper.UserMapper;
import cn.kgc.springboot.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/11/2
 */
@Service
@Slf4j  //  使用lombok提供的注解自动生成 log对象 实现日志的打印
public class UserServiceImpl  implements UserService {

    //private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);

    @Autowired(required = false)
    private UserMapper userMapper;
    public List<User> findAll(){
        List<User> all = userMapper.findAll();

        // 查询结果打印
        for (User user : all) {
            //System.out.println("user = " + user);
            // 通过dubug级别的日志  打印用户信息到控制台  {}  数据动态拼接符号
            //logger.debug("user={}",user);
            log.debug("user={}",user);
        }

        return  all;
    }

    @Override
    public PageInfo<User> userPage(Integer page, Integer limit) {
        //开启分页插件
        PageHelper.startPage(page, limit);
        List<User> all = userMapper.findAll();
        PageInfo<User> userPageInfo = new PageInfo<>(all);
        return userPageInfo;
    }


}
